from pygame.sprite import Sprite
import pygame
class Bar (Sprite):
    old_pos = None
    new_pos = None
    def __init__(self):
        pygame.sprite.Sprite.__init__(self) #call Sprite initializer
        self.image = pygame.image.load('bar.png').convert()
        self.image.set_colorkey(self.image.get_at((0,0)))
        self.rect = self.image.get_rect()
        self.rect = self.rect.move((0,385))
    
    def move(self, event):
        x,y = event.pos
        
        self.old_pos = self.new_pos
        self.new_pos = x
        
        if ( x < 800 - self.rect.width ):
            self.rect = pygame.Rect(x, 385, self.rect.width, self.rect.height)
    
    def get_velocity(self ):
        return self.new_pos - self.old_pos